<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		 <meta name="viewport" content="width=device-width,initial-scale=1.0">
		<title>编辑发票内容</title>
		<link href="css/index.css" rel="stylesheet" />
	</head>
	<body>
	<div class="wrapEdit">
		<div class="headTitle">
		<img onclick="goback()" src="./img/leftArrow.jpg" />
		<p>编辑发票内容</p>
       	</div>
		<p class="pHead">
			<small>*</small><span>发票抬头</span><input maxlength="60" class="headInput" placeholder="请填写发票抬头" />
		</p>
		<p class="pMail">
			<small>*</small><span>电子邮箱</span><input maxlength="50" class="emailInput" placeholder="请填写电子邮箱" />
		</p>
		<p class="pAddress"><span>地址</span><input maxlength="100" class="addressInput" placeholder="请填写地址,非必填" /></p>
		<p class="pPhone"><span>电话</span><input maxlength="20" class="phoneInput" placeholder="请填写电话,非必填" /></p>
		<button class="sure">确定</button>
		<span class="spanDel">删除</span>
	</div>
	
	<div class="wrapBomb2" style="display: none;">
		<div class="bombContent">
			<span class="spanTitle" style="height: 0.8rem;"></span>
			<p class="pContent"><span class="spanContent1">确定删除该发票抬头吗?</span></p>
			<button class="cancle">取消</button>
			<button class="sure">删除</button>
		</div>
	</div>
	
	<script src="js/jquery.min.js"></script>
	<script src="js/oldPublic.js"></script>
	<script src="js/code.js"></script>
	<script src="js/security.js"></script>
	<script>
	var login_name = sessionStorage.getItem('login_name');
	var telphone = sessionStorage.getItem('telphone');
	var orgcode = sessionStorage.getItem('orgcode');
	var title_id = window.location.href.split('?')[1].split('=')[1];
			$.ajax({
				type:"post",
				url:sessionStorage.getItem('ipconfig'),
				data:JSON.stringify({data:encryptByDESModeEBC(JSON.stringify({"tag": "9102", 'login_name': login_name, 'telphone': telphone, 'bus_type': '1','orgcode':orgcode }))}),
				contentType: "application/json;charset=utf-8",
				success:function(data){
					console.log(data);
					if(data.result=='00'){
					 var title_info = JSON.parse(data.title_info);
					 for(var i=0;i<title_info.length;i++){
					 	if(title_id==title_info[i].title_id){
					 		$('.headInput').val(title_info[i].name);
					 		$('.emailInput').val(title_info[i].email);
					 		$('.addressInput').val(title_info[i].adress);
					 		$('.phoneInput').val(title_info[i].telphone_no);
					 	}
					 }
					}else{
						showWarn(data.description);
					}
					
				}
			});
			
			$('.sure').click(function(){
				var reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
				var headInput = $('.headInput').val();
				var emailInput = $('.emailInput').val();
				var addressInput = $('.addressInput').val();
				var phoneInput = $('.phoneInput').val();
				if(headInput.length==0){
					showWarn('请输入发票抬头');
					return;
				}
				if(!reg.test(emailInput)){
					showWarn('请输入正确的邮箱');
					return;
				}
				$.ajax({
				type:"post",
				url:sessionStorage.getItem('ipconfig'),
				data:JSON.stringify({data:encryptByDESModeEBC(JSON.stringify({"tag": "9102", 'login_name': login_name, 'telphone': telphone, 'bus_type': '3', 'title_type': '0', 'name': headInput, 'email': emailInput, 'adress': addressInput, "telphone_no": phoneInput,'title_id':title_id,'orgcode':orgcode }))}),
				success:function(data){
					console.log(data);
					if(data.result=='00'){
						showWarn('修改成功');
						setTimeout(function(){
							history.back();
						},1000)
					}else{
						showWarn(data.description);
					}
				}
			  });
			})
			
			$('.spanDel').click(function(){
			$('.wrapBomb2').show();
			})
			
			$('.wrapBomb2').find('.cancle').click(function(){
				$('.wrapBomb2').hide();
			})
			$('.wrapBomb2').find('.sure').click(function(){
				$('.wrapBomb2').hide();
				$.ajax({
				type:"post",
				url:sessionStorage.getItem('ipconfig'),
				data:JSON.stringify({data:encryptByDESModeEBC(JSON.stringify({"tag": "9102", 'login_name': login_name, 'telphone': telphone, 'bus_type': '4','title_id':title_id,'orgcode':orgcode }))}),
				success:function(data){
					console.log(data);
					if(data.result=='00'){
						showWarn('删除成功');
						setTimeout(function(){
							history.back();
						},1000)
					}else{
						showWarn(data.description);
					}
				}
			  });
			})
			
	</script>
</body>
</html>




